package vn.edu.vnu.sort;

import java.util.ArrayList;
import java.util.Random;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class CreateArray extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_create_array);
        
        TextView tv = (TextView) findViewById(R.id.textView2);
        TextView tv3 = (TextView) findViewById(R.id.textView3);
        
        Intent localIntent = getIntent();
        Bundle myBundle = localIntent.getExtras();
        tv.setText(myBundle.getString("text"));
        
        int size = myBundle.getInt("number");
        final int alg = myBundle.getInt("alg");
        tv3.setText("Chosen array for sorting. There are " + size + " number");
        
        Random generator = new Random();
        ArrayList<Integer> mList = new ArrayList<Integer>();
        
        for(int i = 0; i < size; i++) {
        	mList.add(generator.nextInt(10) + 1);
        }
        
        String myArray = "";
        for(int i = 0; i < size; i++) {
        	myArray += mList.get(i) + " ";
        }
        @SuppressWarnings("unchecked")
		final ArrayList<Integer> list = (ArrayList<Integer>) mList.clone();
        
        TextView tv4 = (TextView) findViewById(R.id.textView4);
        tv4.setText(myArray);
        Button btn = (Button) findViewById(R.id.button1);
        btn.setOnClickListener(new OnClickListener() {
			
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent intent = new Intent();
		        intent.setClassName("vn.edu.vnu.sort", "vn.edu.vnu.sort.Result");
		        intent.putExtra("alg", alg);
		        intent.putExtra("list", list);
		        startActivity(intent);
			}
		});
    }
}
